package com.xlh.service.impl;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Service
@Slf4j
public class OrderServiceImpl3 {
    int i = 0;
    /*  //定义一个资源
     //定义当资源内部发生异常的时候的处理逻辑
     //blockHandler  定义当资源内部发生了BlockException应该进入的方法[捕获的是Sentinel定义的异常]
     //fallback      定义当资源内部发生了Throwable应该进入的方法
     @SentinelResource(
             value = "message",
             blockHandlerClass = OrderServiceImpl3BlockHandler.class,
             blockHandler = "blockHandler",
             fallbackClass = OrderServiceImpl3Fallback.class,
             fallback = "fallback"
     )
     public String message(String name) {
     }*/
     @SentinelResource(
             value = "message",
             blockHandler = "blockHandler",
             fallback = "fallback",
             blockHandlerClass = OrderServiceImpl3BlockHandler.class,
             fallbackClass = OrderServiceImpl3Fallback.class
              )
     public String message(String name){
         i++;
        /* if (i % 3 == 0) {
             throw new RuntimeException();
         }*/
         return "message";
     }
 /*    public String blockHandler(String name, BlockException blockException){
        log.error("触发了blockException异常",blockException);
         return "blockException";
     }
     public  String fallback(String name ,Throwable throwable){
         log.error("触发了Throwable异常",throwable);
     return  "触发了Throwable异常";
     }*/
}
